﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BaoShouTangServer
{
    public class GlobalExceptionFilter : IExceptionFilter
    {
        private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
        public void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            Logger.Error("Message:" + filterContext.Exception.Message);
            Logger.Error("StackTrace:" + filterContext.Exception.StackTrace);

            //ReturnMsg rm = new ReturnMsg();
            //rm.MessageCode = "501";
            //rm.MessageString = $"{filterContext.Exception.Message}";
            //rm.BillCode = "";

            // 构造要返回给客户端的 JSON 数据
           
            var result = new JsonResult { Data = new { msg = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

            filterContext.Result = result;
        }
    }
}